﻿using System;
using System.Data;


namespace E2_WEBSITE.Code.Admin
{
    public class UserController
    {
        UserDataAccess m_DataAccess;

        public UserController()
        {
            m_DataAccess = new UserDataAccess();
        }

        public DataTable GetSimpleUsers()
        {
            try
            {
                return m_DataAccess.GetSimpleUsers();
            }
            catch (Exception)
            {

                throw;
            }
        }

        public DataTable GetUsers()
        {
            try
            {
                return m_DataAccess.GetUsers();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public UserInfo GetUserInfo(int uid)
        {
            try
            {
                return m_DataAccess.GetUserById(uid);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool DeleteUser(int id)
        {
            try
            {
                return m_DataAccess.DeleteUser(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public bool UpdateUser(int uid, UserInfo user)
        {
            try
            {
                return m_DataAccess.UpdateUser(uid, user);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool CheckPassword(int uid, string pass)
        {
            try
            {
                return m_DataAccess.CheckPassword(uid, pass);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool ChangePassword(int uid, string oldPass, string newPass)
        {
            try
            {
                if (m_DataAccess.CheckPassword(uid, oldPass))
                {
                    return m_DataAccess.ChangePassword(uid, newPass);
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool InsertUser(UserInfo user, string pass)
        {
            try
            {
                int uid = m_DataAccess.GetUserFreeId();
                return m_DataAccess.InsertUser(uid, pass, user);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public string ResetPassword(int uid, string reset)
        {
            try
            {
                return m_DataAccess.ResetPassword(uid, reset);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public DataTable GetUserType()
        {
            try
            {
                return m_DataAccess.GetUserType();
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}